﻿<script type="text/javascript">

    //#region 为Combobox增加--请选择--
    function EUIcombobox(jqS, o) {
        $.ajax({
            type: "POST",
            async: false,
            url: o.url,
            dataType: "JSON",
            success: function (data1, textStatus, jqXHR) {
                o.data = o.OneOption.concat(data1);
                delete o.url;
                delete o.OneOption;
                $(jqS).combobox(o);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("获取字典数据失败！可能是已经超时，请重新登录！");
            }
        });
    }



    function initcombo() {
        //#region 分中心 初始化
        EUIcombobox("#txtCenterCode", {
            url: '@Url.Content("~/Medical/GetCenter/")',
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }],
            onSelect: function (rec) {
                var urlstation = '@Url.Content("~/Medical/GetStation?code=")' + rec.ID;
                EUIcombobox("#txtStationCode", {
                    url: urlstation,
                    valueField: 'ID',
                    textField: 'Name',
                    editable: false,
                    OneOption: [{
                        ID: "",
                        Name: "--请选择--"
                    }]
                });
            }
        });


        //#region 出车分站 初始化
        EUIcombobox("#txtStationCode", {
            url: '@Url.Content("~/Medical/GetStation?code=")',
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }],
            onSelect: function (rec) {
                var zz = '@Url.Content("~/CM/CarBasicInfo/getPlateByStationID?stationCode=")' + rec.ID;
                EUIcombobox("#txtPlateNumber", {
                    url: zz,
                    valueField: 'AmbulanceCode',
                    textField: 'PlateNumber',
                    editable: false,
                    OneOption: [{
                        AmbulanceCode: "",
                        PlateNumber: "--请选择--"
                    }]
                });
                var zzz = '@Url.Content("~/CM/CarBasicInfo/getPlateByStationID?stationCode=")' + rec.ID;
                EUIcombobox("#txtCarNumber", {
                    url: zzz,
                    valueField: 'AmbulanceCode',
                    textField: 'CarNumber',
                    editable: false,
                    OneOption: [{
                        AmbulanceCode: "",
                        CarNumber: "--请选择--"
                    }]
                });
            }
        });

        //车辆牌号 初始化
        EUIcombobox("#txtPlateNumber", {
            url: '@Url.Content("~/CM/CarBasicInfo/getPlateByStationID?stationCode=")',
            valueField: 'AmbulanceCode',
            textField: 'PlateNumber',
            editable: true,
            OneOption: [{
                AmbulanceCode: "",
                PlateNumber: "--请选择--"
            }],
            onSelect: function (rec) {
                @*var zzb = '@Url.Content("~/CM/CarBasicInfo/getCarNumberByID?ID=")' + rec.AmbulanceCode;
                $("#txtCarNumber").combobox({
                    url: zzb,
                    valueField: 'AmbulanceCode',
                    textField: 'CarNumber',
                    editable: false

                });*@
                $("#txtCarNumber").combobox('setValue', rec.AmbulanceCode);  //根据选择车牌对应的ID ，给车辆编号赋值

                ambCode = rec.AmbulanceCode;  //实质就是传基础表的ID

            }
        });
        EUIcombobox("#txtCarNumber", {       //选择车辆编号的联动 初始化
            url: '@Url.Content("~/CM/CarBasicInfo/getCarNumberByID?ID=")',
            valueField: 'AmbulanceCode',
            textField: 'CarNumber',
            editable: true,
            OneOption: [{
                AmbulanceCode: "",
                CarNumber: "--请选择--"
            }],
            onSelect: function (rec) {
                @*var zzc = '@Url.Content("~/CM/CarBasicInfo/getCarNumberByID?ID=")' + rec.AmbulanceCode;

                $("#txtPlateNumber").combobox({
                    url: zzc,
                    valueField: 'AmbulanceCode',
                    textField: 'PlateNumber',
                    editable: false
                });*@

                $("#txtPlateNumber").combobox('setValue', rec.AmbulanceCode);  //根据选择车辆编号对应的ID，给车牌号赋值 初始化
                ambCode = rec.AmbulanceCode;  //实质就是传基础表的ID

            }
        });

        var urlstr = '@Url.Content("~/CM/CarBasicInfo/getDictionarybyTypeID?TypeID=CMACDLevel")';   //事故等级初始化
        $.EUIcombobox("#txtAccidentLevel", {
            url: urlstr,
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }]

        });

        var urlstr = '@Url.Content("~/CM/CarBasicInfo/getDictionarybyTypeID?TypeID=CMACDResponsibility")';   //责任情况初始化
        $.EUIcombobox("#txtResponsibility", {
            url: urlstr,
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }]
            ,
            onSelect: function (record) {
                if (record.Name == '无责') {

                    $('#txtReportNumber').textbox({ required: false });
                } else {
                    $('#txtReportNumber').textbox({ required: true });
                }
            },

        });
        //是否伤人  2016-03-01
        $('#txtIFHurt').combobox({  //路程计算方式
            valueField: 'ID',
            textField: 'Name',
            method: 'get',
            panelHeight: 'auto',
            editable: false,
            data: [
           {
               ID: '',
               Name: '--请选择--'
           },
          {
              ID: '否',
              Name: '否'
          },
          {
              ID: '是',
              Name: '是'
          }
            ]
        });


        //肇事人的所在分中心，所在分站的下拉框内容 初始化
        EUIcombobox("#txtPersonCenterCode", {
            url: '@Url.Content("~/Medical/GetCenter/")',
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }],
            onSelect: function (rec) {
                var urlstation = '@Url.Content("~/Medical/GetStation?code=")' + rec.ID;
                EUIcombobox("#txtPersonStationCode", {
                    url: urlstation,
                    valueField: 'ID',
                    textField: 'Name',
                    editable: false,
                    OneOption: [{
                        ID: "",
                        Name: "--请选择--"
                    }]
                });
            }
        });
        EUIcombobox("#txtPersonStationCode", {
            url: '@Url.Content("~/Medical/GetStation?code=")',
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }]
        });




        $('#dModCou').html('1500');
        $('#deModCou').html('1500');
        $('#ieModCou').html('700');
        $('#rModCou').html('500');


    } //初始化结束


    function getEditACD(EditID) {
        $.ajax({
            type: 'POST',
            url: '@Url.Content("~/CM/AccidentManage/getEditACD")',
            data:
                {
                    EditID: EditID
                },
            dataType: "json",
            success: function (jsData) {

                $('#txtCenterCode').combobox('setValue', jsData.Info.CenterCode);
                $('#txtStationCode').combobox('setValue', jsData.Info.StationCode);
                $('#txtPlateNumber').combobox('setValue', jsData.Info.PlateNumber);
                $('#txtCarNumber').combobox('setValue', jsData.Info.CarNumber);
                $('#txtAccidentTime').datetimebox('setValue', jsData.Info.AccidentTime);

                $('#txtAccidentAddress').textbox('setValue', jsData.Info.AccidentAddress);
                $('#txtAccidentLevel').combobox('setValue', jsData.Info.AccidentLevel);

                $('#txtResponsibility').combobox('setValue', jsData.Info.Responsibility ? jsData.Info.Responsibility : "");

                //textarea没有value属性，只能这样赋值
                document.getElementById("txtDescription").value = jsData.Info.Description ? jsData.Info.Description : "";
                document.getElementById("txtDealExplain").value = jsData.Info.DealExplain ? jsData.Info.DealExplain : "";
                document.getElementById("txtInsuranceExplain").value = jsData.Info.InsuranceExplain ? jsData.Info.InsuranceExplain : "";
                document.getElementById("txtRemark").value = jsData.Info.Remark ? jsData.Info.Remark : "";

                $('#txtReportNumber').textbox('setValue', jsData.Info.ReportNumber);
                $('#txtEndReportPerson').textbox('setValue', jsData.Info.EndReportPerson);

                if (jsData.Info.EndReportDate != null) {

                    var zEndReportDate = $.formatDate(jsData.Info.EndReportDate);
                    $('#txtEndReportDate').datebox('setValue', zEndReportDate);
                }
                $('#txtPersonName').textbox('setValue', jsData.Info.PersonName);
                $('#txtPersonWorkCode').textbox('setValue', jsData.Info.PersonWorkCode);//
                $('#txtPersonCenterCode').combobox('setValue', jsData.Info.PersonCenterCode);//
                $('#txtPersonStationCode').combobox('setValue', jsData.Info.PersonStationCode);//
                $('#txtIFHurt').combobox('setValue', jsData.Info.IFHurt);// 2016-03-01

            }
        })
    }





    function submitAddForm() { //提交新增方法

        $('#formSubmit').form('submit', {
            url: '@Url.Content("~/CM/AccidentManage/SaveNewAccident")',
            queryParams: {
                ambid: ambCode
            },
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (data) {
                var jsData = $.parseJSON(data);

                $.showMsg(jsData.Message, "系统提示", function () { });
                $('#AccidentDetailDialog').dialog('close');
                $('#gridAccidentManageList').datagrid('reload');
                ClearForm();

            }
        });
    }

    function submitEditForm() { //修改页面提交保存
        $('#formSubmit').form('submit', {
            url: '@Url.Content("~/CM/AccidentManage/EditACD")',
            queryParams: {
                EditID: EditID

            },//提交的ID
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (data) {
                var jsData = $.parseJSON(data);

                $.messager.defaults = { ok: "确定", cancel: "取消" };
                $.showMsg(jsData.Message, "系统提示", function () { });
                $('#AccidentDetailDialog').dialog('close');
                $('#gridAccidentManageList').datagrid('reload');
                ClearForm();


            }
        });
    }

    function ClearForm() {

        var ambCode = null; //全局变量，选择的车辆ID ，从车辆基础表中来。
        var EditID = null;


        $('#txtCenterCode').combobox('clear');
        $('#txtStationCode').combobox('clear');
        $('#txtPlateNumber').combobox('clear');
        $('#txtCarNumber').combobox('clear');
        $('#txtAccidentTime').datetimebox('clear');
        $('#txtAccidentAddress').textbox('clear');
        $('#txtAccidentLevel').combobox('clear');
        $('#txtResponsibility').combobox('clear');
        $('#txtDescription').val('');
        $('#txtDealExplain').val('');
        $('#txtInsuranceExplain').val('');
        $('#txtRemark').val('');
        $('#txtReportNumber').textbox('clear');
        $('#txtEndReportPerson').textbox('clear');
        $('#txtEndReportDate').datebox('clear');
        $('#txtPersonName').textbox('clear');
        $('#txtPersonWorkCode').textbox('clear');
        $('#txtPersonCenterCode').combobox('clear');
        $('#txtPersonStationCode').combobox('clear');
        $('#txtIFHurt').combobox('clear');

    }


    function TxtMaxlength(MaxCount, textareaName, remainID) {

        if (MaxCount == null || typeof (Number(MaxCount)) !== "number") MaxCount = 0;

        var Objs = textareaName;

        // var Objs = formSubmit.Description;
        var ObjCou = Objs.value.length;

        remainID.html(MaxCount - ObjCou);
        // formSubmit.ModCou.value = MaxCount - ObjCou;
        if (ObjCou > MaxCount) {
            Objs.value = Objs.value.substr(0, MaxCount);
        }
    }


</script>

<div id="AccidentDetailDialog" class="easyui-dialog" title="事故明细" data-options="modal:true,collapsible:false,minimizable:false,maximizable:false,closed:true,resizable:false,iconCls:'icon-custom-cWuZiWeiHu'" style="width: 1000px; height: auto; padding: 10px;">
    <form id="formSubmit" method="post">
        <input name="ID" id="txtID" type="hidden">
        <input name="AmbulanceCode" id="txtAmbulanceCode" type="hidden">
        <div style="width: 99%; height: auto;">
            <table style="width:99%;height:auto;">
                <tr>
                    <td valign="top">

                        <div class="easyui-accordion" style="width: 99%; height: auto;">
                            <div title="事故信息" data-options="iconCls:'icon-save'" style="overflow:auto;padding:5px;">
                                <table border="0">
                                    <tr><td style="color:#0099FF;">事故信息</td></tr>
                                    <tr>

                                        <td style="width:75px" align="right">分中心：</td>
                                        <td style="width:145px" align="left" valign="middle">
                                            <input class="easyui-combobox" style="width: 120px" name="CenterCode" id="txtCenterCode" data-options="panelHeight:'auto'">
                                        </td>
                                        <td style="width:75px" align="right">  分站：</td>
                                        <td style="width:125px">
                                            <input class="easyui-combobox" style="width: 120px" name="StationCode" id="txtStationCode">

                                        </td>
                                        <td align="right" style="width:75px">
                                            车牌号码：
                                        </td>
                                        <td style="width:125px">
                                            <input class="easyui-combobox" style="width: 120px" name="PlateNumber" id="txtPlateNumber" data-options="required:true">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right">
                                            事故时间：
                                        </td>
                                        <td colspan="3">
                                            <input class="easyui-datetimebox" style="width: 170px" name="AccidentTime" id="txtAccidentTime" data-options="required:true">
                                        </td>

                                        <td align="right">
                                            车辆编号：
                                        </td>
                                        <td>
                                            <input class="easyui-textbox" style="width: 120px" name="CarNumber" id="txtCarNumber">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right">
                                            事故地点：
                                        </td>
                                        <td colspan="5">
                                            <input name="AccidentAddress" id="txtAccidentAddress" class="easyui-textbox" style="width:550px" data-options="required:true" />

                                        </td>
                                    </tr>

                                    <tr>
                                        <td align="right">
                                            事故等级：
                                        </td>
                                        <td>
                                            <input class="easyui-combobox" style="width: 140px" name="AccidentLevel" id="txtAccidentLevel" data-options="panelHeight:'auto'">
                                        </td>
                                        <td align="right">
                                            责任情况：
                                        </td>
                                        <td>
                                            <input class="easyui-combobox" style="width: 120px" name="Responsibility" id="txtResponsibility" data-options="panelHeight:'auto'">
                                        </td>
                                        <td align="right">
                                            是否伤人：
                                        </td>
                                        <td>
                                            <input class="easyui-combobox" style="width: 120px" name="IFHurt" id="txtIFHurt" data-options="panelHeight:'auto'">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="6" height="220px">

                                            <div id="tt" class="easyui-tabs" data-options="border:false" style="width:620px;height:210px;padding-top:6px;">
                                                <div title="事故说明" data-options="iconCls:'icon-redo',closable:false" style="padding:2px;">
                                                    <table>
                                                        <tr>
                                                            <td>
                                                                <textarea name="Description" id="txtDescription" style="font-size: medium; width: 600px" rows="7" onpropertychange="TxtMaxlength(1500, formSubmit.Description, $('#dModCou'))"></textarea>
                                                                @*<textarea name="Description" id="txtDescription" style="font-size: medium; width: 600px" rows="7" onpropertychange=textCounter(upbook.words, 50)></textarea>*@
                                                            </td>
                                                        </tr>
                                                        <tr><td>您可以输入:<label id="dModCou" style="color:red"> </label>个字！</td></tr>
                                                    </table>
                                                </div>
                                                <div title="处理过程" data-options="iconCls:'icon-redo',closable:false" style="padding:2px;">

                                                    <table>
                                                        <tr>
                                                            <td>
                                                                <textarea name="DealExplain" id="txtDealExplain" style="font-size: medium; width: 600px" rows="7" onpropertychange="TxtMaxlength(1500, formSubmit.DealExplain, $('#deModCou'))"></textarea>
                                                            </td>
                                                        </tr>
                                                        <tr><td>您可以输入:<label id="deModCou" style="color:red"> </label>个字！</td></tr>
                                                    </table>

                                                </div>
                                                <div title="保险理赔" data-options="iconCls:'icon-redo',closable:false" style="padding:2px;">

                                                    <table>
                                                        <tr>
                                                            <td>
                                                                <textarea name="InsuranceExplain" id="txtInsuranceExplain" style="font-size: medium; width: 600px" rows="7" onpropertychange="TxtMaxlength(700, formSubmit.InsuranceExplain, $('#ieModCou'))"></textarea>
                                                            </td>
                                                        </tr>
                                                        <tr><td>您可以输入:<label id="ieModCou" style="color:red"> </label>个字！</td></tr>
                                                    </table>
                                                </div>
                                                <div title="备注" data-options="iconCls:'icon-redo',closable:false" style="padding:2px;">

                                                    <table>
                                                        <tr>
                                                            <td>
                                                                <textarea name="Remark" id="txtRemark" style="font-size: medium; width: 600px" rows="7" onpropertychange="TxtMaxlength(500, formSubmit.Remark, $('#rModCou'))"></textarea>
                                                            </td>
                                                        </tr>
                                                        <tr><td>您可以输入:<label id="rModCou" style="color:red"> </label>个字！</td></tr>
                                                    </table>

                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </td>
                    <td valign="top" width="270px">
                        <table border="0" style="width:270px">
                            <tr>
                                <td>
                                    <div class="easyui-accordion" style="width: 99%; height:inherit;">
                                        <div title="其他信息" data-options="iconCls:'icon-save'" style="overflow:auto;padding:5px;">
                                            <table id="ReportInfo">
                                                <tr style="height:30px"><td style="color:#0099FF;">报案信息</td></tr>
                                                <tr style="height:30px">
                                                    <td>
                                                        报案号：
                                                    </td>
                                                    <td>
                                                        <input class="easyui-textbox" style="width: 150px" name="ReportNumber" id="txtReportNumber" data-options="required:true">
                                                    </td>
                                                </tr>
                                                <tr style="height:30px">
                                                    <td>
                                                        结案人:
                                                    </td>
                                                    <td>
                                                        <input class="easyui-textbox" style="width: 150px" name="EndReportPerson" id="txtEndReportPerson">
                                                    </td>

                                                </tr>
                                                <tr style="height:30px">
                                                    <td>
                                                        结案日期:
                                                    </td>
                                                    <td>
                                                        <input class="easyui-datebox" style="width: 150px" name="EndReportDate" id="txtEndReportDate">
                                                    </td>
                                                </tr>

                                            </table>
                                            <table id="CausePerson">
                                                <tr style="height:30px"><td style="color:#0099FF;">肇事人员</td></tr>
                                                <tr style="height:30px">
                                                    <td>
                                                        姓名：
                                                    </td>
                                                    <td>
                                                        <input class="easyui-textbox" style="width: 140px" name="PersonName" id="txtPersonName">
                                                    </td>
                                                </tr>
                                                <tr style="height:30px">
                                                    <td>
                                                        工号:
                                                    </td>
                                                    <td>
                                                        <input class="easyui-textbox" style="width: 140px" name="PersonWorkCode" id="txtPersonWorkCode">
                                                    </td>

                                                </tr>
                                                <tr style="height:30px">
                                                    <td>
                                                        所在分中心:
                                                    </td>
                                                    <td>
                                                        <input class="easyui-combobox" style="width: 140px" name="PersonCenterCode" id="txtPersonCenterCode">
                                                    </td>
                                                </tr>
                                                <tr style="height:30px">
                                                    <td>
                                                        所在分站:
                                                    </td>
                                                    <td>
                                                        <input class="easyui-combobox" style="width: 140px" name="PersonStationCode" id="txtPersonStationCode">
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <table style="width:270px" border="0">
                                        <tr>
                                            <td align="center">
                                                <a href="javascript:void(0)" id="btnadd" style="width:90px;height:40px" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="submitAddForm();">确定新增</a>

                                                <a href="javascript:void(0)" id="btnedit" style="width:90px;height:40px" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="submitEditForm();">确定修改</a>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</div>
